import request from '@/utils/request'
import type { Response, PageDataList } from '@/utils/type'
import type { addBaseMapParams } from '@/api/back-management/basemap/interface'

export interface BaseMapDataResp {
  createTime: string
  fileId?: string
  fileUrl?: string
  isDefault: 0 | 1
  mapName: string
  mapUrl: string
  pkid: string
  serviceType: 'wmts' | 'wms' | ''
  updateTime?: string
}

/**
 * 更新用户
 *
 * @param {addBaseMapParams} params 新增参数
 *
 */
export const addBaseMap = (params: addBaseMapParams) => {
  return request('/resource/mapbase/add', {
    method: 'POST',
    data: params,
  }) as Promise<Response<string>>
}

/**
 * 上传缩略图
 *
 * @param {addBaseMapParams} params 新增参数
 *
 */
export const uploadMapFile = (params: any) => {
  return request('/resource/file/upload/file', {
    method: 'POST',
    data: params,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  }) as Promise<Response<string>>
}

/**
 * 用户列表
 *
 * @param {any} params 新增参数
 *
 */
export const queryMapList = (
  params: any
): Promise<Response<PageDataList<BaseMapDataResp>>> => {
  return request('/resource/mapbase/query', {
    method: 'GET',
    params,
  })
}

/**
 * 底图更新
 *
 */
export const updateBaseMap = (pkid: string, params: addBaseMapParams) => {
  return request(`/resource/mapbase/update/${pkid}`, {
    method: 'PUT',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 底图删除
 *
 */
export const deleteBaseMap = (pkid: string) => {
  return request(`/resource/mapbase/delete?pkid=${pkid}`, {
    method: 'DELETE',
  }) as Promise<Response<any>>
}
